//
//  receiveFirCirSendCom.m
//  tcpoctest
//
//  Created by gump on 5/10/13.
//  Copyright (c) 2013 gump. All rights reserved.
//

#import "receiveFirCirSendCom.h"

#import "FirCirCommentInfo.h"
#import "FirCirSendCommentInfo.h"
#import "FirCirLocalInfo.h"

#import "FirCirCommentDataSource.h"
#import "FirendCircleDataSource.h"
#import "FirCirLocalResourceDataSource.h"

#import "FirendCirLocalPathdb.h"



@implementation receiveFirCirSendCom

-(void)processreceive
{
    //回执 74char(1),11char(1)，返回值char(1)，
    //1成功，2发送太多,用户名长度char(1),
    //用户名char(x),评论ID长度char(1),评论IDchar(x)
    
    switch ([logicsb ReadChar]) {
        case FC_SENDNEW:
        {
            FirCirCommentInfo *fccinfo = [[FirCirCommentInfo alloc] init];
            fccinfo.mail = [logicsb ReadUnencodeString];
            fccinfo.commentID = [logicsb ReadUnencodeString];
            
            FirCirSendCommentInfo *fcscinfo = [[DataControl shareControl].fccommentDS SendCommentInfo];
            if (fcscinfo != nil) {
                fccinfo.newsID = fcscinfo.newid;
                fccinfo.speakto = fcscinfo.speakto;
                fccinfo.stIndex = fcscinfo.istindex;
                fccinfo.content = fcscinfo.content;
            }
            fccinfo.speaker = [DataControl shareControl].personDS.uinfo.mail;
            fccinfo.strtime = [[DataControl shareControl].fircirDS greatFCcurTimeString];
            
            if (fccinfo.stIndex == FCG_ONE_SOUND) {
                FirCirLocalInfo *fclinfo = [[FirCirLocalInfo alloc] init];
                fclinfo.resourceID = fccinfo.commentID;
                fclinfo.localpath = fccinfo.content;
                
                [[DataControl shareControl].fcLocalRecDS AddLocalRs:fclinfo];
                [[DataBaseCtrol shareControl].fircirlocaldatabase insertLocalPath:fclinfo];
            }
            
            [[DataControl shareControl] AddComment:fccinfo];
            
            [[DataControl shareControl].UICommendDS addUICommand:UC_FIRCIR_COMMENTSUCCESS];
            
            
            
        }
            break;
        case FC_ADDPICTURE:
        {
            [[DataControl shareControl].UICommendDS addUICommand:UC_FIRCIR_COMMENTFAIL];
        }
            break;
        default:
            break;
    }
    
    [self ShowLog];
}

@end
